function reallocTempProfile(p,n)
  use derived,only:TemperatureProfile
  implicit none

  type(TemperatureProfile),pointer,dimension(:) :: &
       reallocTempProfile,p
  integer,intent(in) :: n
  integer :: i,nold,ierr

  allocate(reallocTempProfile(1:n),stat=ierr)
  if (ierr.ne.0) call abnormal_stop("reallocTempProfile",&
       "Memory allocation cause an error.")

  reallocTempProfile(n)%temp=-1
  reallocTempProfile(n)%loop_condition=-1
  reallocTempProfile(n)%stop_condition=-1
  reallocTempProfile(n)%external_event_flag=0

  if (.not.associated(p)) return

  nold=n-1
  do i=1,nold
     reallocTempProfile(i)%temp=p(i)%temp
     reallocTempProfile(i)%loop_condition=&
          p(i)%loop_condition
     reallocTempProfile(i)%stop_condition=&
          p(i)%stop_condition
     reallocTempProfile(i)%external_event_flag=&
          p(i)%external_event_flag
  end do

  deallocate(p)

  return

end function reallocTempProfile
